package win.timloong.android.carwiki.adapter;

import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import java.io.File;
import java.util.ArrayList;

import win.timloong.android.carwiki.R;
import win.timloong.android.carwiki.util.ImageUtil;

/**
 * Created by tim on 16/7/12.
 */

public class QuanziItemAdapter extends BaseAdapter {
    String[] rls;
    public  QuanziItemAdapter(String[] urls){
       this.rls =urls;
    }


    @Override
    public int getCount() {
        return rls.length<=9?rls.length:9;
    }

    @Override
    public String getItem(int i) {
        return rls[i];
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int pos, View convertView, ViewGroup viewGroup) {
        Holder holder =null;
        if (convertView!=null){
            holder = (Holder) convertView.getTag();
        }else {
            convertView= LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.fragment_quanzi_item_gridview,null);
            holder = new Holder();
            holder.imageView = (ImageView) convertView.findViewById(R.id.quanzi_item_gridview_item);
            convertView.setTag(holder);
        }

        String url = getItem(pos);
        if (url.startsWith("http://")){
            ImageUtil.loadImage(getItem(pos),holder.imageView);
        }else {
            ImageUtil.loadImage(new File(url),holder.imageView);
        }

        return convertView;
    }

    class Holder{
        ImageView imageView;
    }
}
